import {Component, Input, OnInit} from '@angular/core';
import 'src/app/common/common';
import {IImgBlock, Utils} from "../../common/common";

@Component({
  selector: 'app-img-block',
  templateUrl: './img-block.component.html',
  styleUrls: ['./img-block.component.scss']
})
export class ImgBlockComponent implements OnInit {

  @Input() public data!: IImgBlock;

  public likedPop!: boolean;
  public collectedPop!: boolean;

  constructor() {
  }

  ngOnInit(): void {
    this.likedPop = false
    this.collectedPop = false
    if (this.data.imgSrc == undefined || this.data.imgSrc == "") {
      this.data.imgSrc = 'assets/img/ss.webp'
    }
  }

  async likeClick(status: boolean): Promise<void> {
    this.data.likeCount += status ? 1 : -1;
    this.data.liked = status
    this.likedPop = this.data.liked
    await Utils.asyncSleep(1500)
    this.likedPop = false
  }

  async collectClick(status: boolean): Promise<void> {
    this.data.collectCount += status ? 1 : -1;
    this.data.collected = status
    this.collectedPop = this.data.collected
    await Utils.asyncSleep(1500)
    this.collectedPop = false
  }
}
